#include <pcap.h>

#include "pcap_task.h"
#include "log.h"
#include "msg.h"
#include "pcap_process.h"
#include "sql.h"

//extern unsigned long raw_packet_count = 0;
//extern unsigned long ipv4_packet_count = 0;

int pcap_ops(struct msg *msg)
{
	log_info("begin pcap_ops.");

	return 0;
}

void *pcap_main(void *data)
{
	log_info("begin pcap_loop.");
	pcap_t *pcap_handle = core_conf.pcap_handle;
	if (pcap_handle == NULL) {
		log_error("pcap_handle is NULL.");
		log_error("pcap_task start failed.");
		/* TODO:kill task */
		return NULL;
	}

	sql_init();

	int res;
	res = sql_query("create table pcapTableInfo(id int, tableName char(128))");
	if (res) {
		log_print("sql_query error: %d, %s\n", sql_errorno(), sql_error());
	}
	
	pcap_loop(pcap_handle, -1, &pcap_task_packet_process, NULL);
	
	/* NOT REACHED HERE */

	return NULL;
}
